package com.simsuni.concept;

import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;

import com.jake.rcp.gef.model.GefModel;
import com.jake.rcp.gef.model.NodeModel;
import com.simsuni.core.exception.NullPointException;

public class SimEntity extends NodeModel{
	/**
	 * 
	 */
	private static final long serialVersionUID = -1602898988662190540L;
	private List<SimAttribute> attributes = new ArrayList<SimAttribute>();
	
	
	public SimEntity(PropertyChangeListener listener) {
		super(listener);
	}
	public SimEntity() {
		super();
	}
	public SimEntity(String name) {
		super(name);
	}
	public SimEntity(String name, int x, int y, PropertyChangeListener listener) {
		super(name, x, y, listener);
	}

	public List<SimAttribute> getAttributes() {
		return attributes;
	}

	public void setAttributes(List<SimAttribute> attributes) throws NullPointException{
		if(attributes == null){
			throw new NullPointException();
		}
		this.attributes = attributes;
	}
	public void addAttribute(SimAttribute attribute){
		this.attributes.add(attribute);
	}
	public void removeAttribute(String name){
		for(SimAttribute attribute : attributes){
			if(name.equals(attribute.getName())){
				attributes.remove(attribute);
				break;
			}
		}
	}
	public void addEntity(SimEntity entity){
		getChildren().add(entity);
	}
	public SimEntity getEntity(String name){
		for(GefModel entity: getChildren()){
			if(entity.getName().equals(name)){
				return (SimEntity)entity;
			}
		}
		return null;
	}
	public List<GefModel> getChildren(){
		
		return super.getChildList();
	}
}
